package org.example.producer;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.SneakyThrows;

public class RabbitMqProducer {
    @SneakyThrows
    public static void creatrRabbitMqProducer() {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("admin");
        factory.setPassword("10086");
        factory.setHost("miaomiaole");
        factory.setPort(7672);
        factory.setVirtualHost("/");
        // 建立到代理服务器连接
        Connection connection = factory.newConnection();
        // 创建信道
        Channel channel = connection.createChannel();
        // 声明交换器
        channel.exchangeDeclare("directExchange", "direct", true);

        channel.basicPublish("directExchange", "directRouteKey", null, "hello RabbitMq".getBytes());

        channel.close();
        connection.close();
    }
}
